﻿using ch08.binary.module;

namespace ch08.binary.wasm_reader
{
    public partial struct WasmReader
    {
        // elem sec
        private Elem[] ReadElemSec()
        {
            var vec = new Elem[ReadVarU32()];
            for (var i = 0; i < vec.Length; i++)
            {
                vec[i] = ReadElem();
            }

            return vec;
        }

        private Elem ReadElem()
        {
            return new()
            {
                Table = ReadVarU32(),
                Offset = ReadExpr(),
                Init = ReadIndices()
            };
        }
    }
}